import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author Yin_JC
 * @PackageName:PACKAGE_NAME
 * @Class:StringLearning
 * @Description:
 * @date 2020/3/3 8:04
 */

class Person{
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}



public class StringLearning {

    @Test
    public void Test1() {
        /**
        * Description:字符串是不可变量，字符串与常量池的问题
        * @author: Yin
        * @date: 2020/3/3 8:29
        */
        String s1 = "abc";
        String s2 = "abc";
        String s3 = new String("abc");
        String s4 = new String("abc");
        System.out.println(s1 == s2);
        System.out.println(s1==s3);
        System.out.println(s1.equals(s3));
        System.out.println(s3 == s4);
        System.out.println(s3.equals(s4));
        System.out.println("******************");
        Person p1 = new Person("yin",18);
        Person p2 = new Person("yin",18);
        System.out.println(p1.name.equals(p2.name));
        System.out.println(p1.name == p2.name);
        System.out.println("***********************");

        String ss1 = "javaEE";
        String ss2 = "hadoop";
        String ss3 = "javaEEhadoop";
        String ss4 = "javaEE" + "hadoop";
        String ss5 = ss1 + "hadoop";
        String ss6 = "javaEE" +ss2;
        String ss7 =  (ss1 + ss2).intern();

        System.out.println(ss3 == ss4);
        System.out.println(ss3 == ss7);
        System.out.println(ss3 == ss5);
        System.out.println(ss3 == ss6);
        System.out.println(ss5 == ss6);
    }

    @Test
    public void Test2() throws UnsupportedEncodingException {
        /**
        * Description:常用方法
         *
         *----------------实例方法-----------------------
         * char charAt(int index)
         * int length()
         * boolean isEmpty()
         * String toLowerCase()
         * String toUpperCase()
         * String trim()
         * boolean equals(Object obj)
         * boolean equalsIgnoreCase(Object obj)
         * String concat(String str) 相当于 +
         * int compareTo(String str) 字典序
         * String subString(int beginIndex,int endIndex)
         *
         *
         * boolean endsWith(String suffix)
         * boolean startsWith(String prefix)
         * boolean startsWith(String prefix, int startIndex)
         * boolean contains(String str)
         * int indexOf(String str/char c)
         * int indexOf(String str, int startIndex) 未找到返回-1
         * int lastIndexOf(String str)
         *
         * String replace(String str1,String Str2)
         * String replace(char c1,char c2)
         * String replaceAll(String regex,String str2) regex是正则表达式
         * String replaceFirst(String regex,String str2)
         * boolean matches(String regex)
         * String[] split(String regex)
         * char[] toCharArray()
         * byte[] getBytes(String encoding)
         *
         * --------------------------------------------------------
         *
         * String --> int : int Integer.parseInt(String str)
         * int --> String : String String.valueOf(int number) 或者 String str = number + ""
        * @author: Yin
        * @date: 2020/3/3 8:30
        */
        String str = "我是一只元宝";
        String str2 = str.substring(2,5);
        System.out.println(str2);
        System.out.println(str.startsWith("我"));
        System.out.println(str.endsWith("宝"));
        System.out.println(str.startsWith("一",2));
        System.out.println(str.contains("我是"));
        System.out.println(str.indexOf('w'));
        String ssss = "hello,number,put";
        for (String sss1:ssss.split("\\,")
             ) {
            System.out.println(sss1);
        }
        String btest = "132ZH欧诺个";
        byte[] bb = btest.getBytes("gbk");
        System.out.println(Arrays.toString(bb));
        System.out.println(new String(bb,"gbk"));
    }
}
